<?php
/**
 * Created by PhpStorm.
 * User: sunburst
 * Date: 2019-07-17
 * Time: 11:23
 */

namespace api\modules\v1_clinic\controllers;

use Yii;
use services\api\ApiBearerAuth;
use services\api\BaseHeaderAuth;
use services\api\JwtService;
use yii\filters\ContentNegotiator;
use yii\rest\Controller;
use yii\web\Response;

class BaseController extends Controller
{
    protected $projectId = 0;

    public function behaviors()
    {
        $behaviors = parent::behaviors();

        $behaviors['contentNegotiator'] = [
            'class' => ContentNegotiator::class,
            'formats' => [
                'application/json' => Response::FORMAT_JSON
            ]
        ];

        $behaviors['authenticator'] = [
            'class' => ApiBearerAuth::class,
        ];

        return $behaviors;
    }

    /**
     * 获取并解析token
     * @return null
     */
    public function getAuthHeaderInfo()
    {
        return JwtService::getJwtInfo(BaseHeaderAuth::$authHeader);
    }

}